package com.dong.combinationMode.service.logic;

import com.dong.combinationMode.model.vo.TreeNodeLink;

import java.util.List;

/**
 * @author DongJiaQi
 * @create 2023/1/5 9:51
 * @Description: 决策抽象类提供基础服务
 */
public abstract class BaseLogic implements LogicFilter {
    @Override
    public Long filter(String matterValue, List<TreeNodeLink> treeNodeLineInfoList) {
        for (TreeNodeLink nodeLine : treeNodeLineInfoList) {
            if (decisionLogic(matterValue, nodeLine)) {
                return nodeLine.getNodeIdTo();
            }
        }
        return 0L;
    }

    /**
     * 决策值的判断
     * @param matterValue
     * @param nodeLink
     * @return
     */
    private boolean decisionLogic(String matterValue, TreeNodeLink nodeLink) {
        String ruleLimitValue = nodeLink.getRuleLimitValue();
        switch (nodeLink.getRuleLimitType()) {
            case 1:
                return matterValue.equals(ruleLimitValue);
            case 2:
                return Double.parseDouble(matterValue) > Double.parseDouble(ruleLimitValue);
            case 3:
                return Double.parseDouble(matterValue) < Double.parseDouble(ruleLimitValue);
            case 4:
                return Double.parseDouble(matterValue) >= Double.parseDouble(ruleLimitValue);
            case 5:
                return Double.parseDouble(matterValue) <= Double.parseDouble(ruleLimitValue);
            default:
                return false;
        }
    }
}
